qui(
    function (require, exports, module) {

        Record.TaskGrid = function (options) {
            this.dao = Record.Dao;
            this.config = Record.Config;
            this.util = Record.Util;
            this.task = Record.Task;
            this.options = options || {};
        };

        Com.inherits(Record.TaskGrid, Ancestor.Grid).extend({
            doInit: function () {
                var self = this;
                var taskArr = [];
                taskArr.push(self.task.getLegoCategory("lego_category"))
                $.each(taskArr, function (index, element) {
                    EpgWeb.ajaxQueue.push(element.regName, element.options);
                })
                EpgWeb.ajaxQueue.afterLoadComplete(function () {
                    self.bindEvent();
                    self.initDateTimePicker();
                    self.initSelect();
                    self.initGrid();
                    self.initFirstQuery();
                })
                EpgWeb.ajaxQueue.startLoad();
            },
            initFirstQuery: function () {
                $("#belong_channel_div").hide();
                try {
                    var channelId = Com.url.getParameter("channel_id");
                    if (channelId != null && !isNaN(channelId)) {
                        $("input[name='EQL_channel.id']").val(channelId);
                    } else {
                        $("#belong_channel_div").show();
                    }
                } catch (e) {
                    console.log("initFirstQuery error");
                }
                var self = this;
                self.query();
            },
            bindEvent: function () {
                var self = this;
                $("button[name=query_btn]").bind("click", function (event) {
                    self.query();
                })
            },
            initDateTimePicker: function () {
                EpgWeb.Util.bindDate("'GES_record_task.task_start_time'", "'LES_record_task.task_start_time'");
            },
            initSelect: function () {
                var resultData = Record.Dao.getDataByName("lego_category");
                var filterArr = [];
                $.each(resultData.data, function (i, element) {
                    filterArr.push({ key: element.id, val: element.name})
                })
                var selectJDom = $("select[name='EQI_col.category_id']");
                $("<option value=''>全部</option>").appendTo(selectJDom);
                $.each(filterArr, function (index, obj) {
                    $("<option>", {
                        value: obj.key,
                        html: obj.val
                    }).appendTo(selectJDom);
                });

                var taskStatusDom = $("select[name='EQI_record_task.task_status']");
                $("<option value=''>全部</option>").appendTo(taskStatusDom);
                for (var key in Record.Config.TASK_STATUS_TAB) {
                    $("<option>", {
                        value: key.replace("key", ""),
                        html: Record.Config.TASK_STATUS_TAB[key]
                    }).appendTo(taskStatusDom);
                }
                ;
            },
            initGrid: function (options) {
                var self = this;
                self.$grid = self.options.$grid;
                var params = self.getParam();
                var gridConfig = self.getGridConfig(self.config.TASK_DATA_LIST);
                options = $.extend(true, {
                    mtype: 'post',
                    postData: $.extend(true, {}, params)
                }, gridConfig, options);
                self.$grid.jqGrid(options);
            },
            query: function (callback) {
                var self = this;
                var $grid = self.$grid;
                var params = self.getParam();
                params.sortType = "desc";
                $grid.jqGrid('setGridParam', {
                    page: 1,
                    datatype: "json",
                    postData: params
                }).trigger('reloadGrid');
            },
            getParam: function () {
                var params = {};
                var inputArr = $('form[role="queryForm"]').find("input[role=query-text]")
                $.each(inputArr, function (i, element) {
                    if (element.value.trim().length > 0) {
                        params [$(element).attr("name")] = element.value.trim()
                    }
                })
                var selectArr = $('form[role="queryForm"]').find("select[role=query-select]")
                $.each(selectArr, function (i, element) {
                    if (element.value.trim().length > 0) {
                        params [$(element).attr("name")] = element.value.trim()
                    }
                })
                params["EQI_record_task.status"] = 1;
                console.log("params:" + JSON.stringify(params));
                return { paramsObj: JSON.stringify(params) };
            }
        });

    }
);